home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntinc20 / ctype.h < prev    next >
C/C++ Source or Header  |  1992-05-15  |  3KB  |  91 lines

  1. /*
  2.  *    ctype.h        Character classification and conversion
  3.  */
  4.  
  5. #ifndef _CTYPE_H
  6. #define _CTYPE_H
  7.  
  8. #ifndef _COMPILER_H
  9. #include <compiler.h>
  10. #endif
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15.  
  16. extern    unsigned char    *_ctype;
  17.  
  18. #define    _CTc    0x01        /* control character */
  19. #define    _CTd    0x02        /* numeric digit */
  20. #define    _CTu    0x04        /* upper case */
  21. #define    _CTl    0x08        /* lower case */
  22. #define    _CTs    0x10        /* whitespace */
  23. #define    _CTp    0x20        /* punctuation */
  24. #define    _CTx    0x40        /* hexadecimal */
  25.  
  26. #define    isalnum(c)    (_ctype[(unsigned char)(c)]&(_CTu|_CTl|_CTd))
  27. #define    isalpha(c)    (_ctype[(unsigned char)(c)]&(_CTu|_CTl))
  28. #define    isascii(c)    !((c)&~0x7F)
  29. #define    iscntrl(c)    (_ctype[(unsigned char)(c)]&_CTc)
  30. #define    isdigit(c)    (_ctype[(unsigned char)(c)]&_CTd)
  31. #define    isgraph(c)    (!(_ctype[(unsigned char)(c)]&(_CTc|_CTs)) && (_ctype[(unsigned char)(c)]))
  32. #define    islower(c)    (_ctype[(unsigned char)(c)]&_CTl)
  33. #define isprint(c)      (!(_ctype[(unsigned char)(c)]&_CTc) && (_ctype[(unsigned char)(c)]))
  34. #define    ispunct(c)    (_ctype[(unsigned char)(c)]&_CTp)
  35. #define    isspace(c)    (_ctype[(unsigned char)(c)]&_CTs)
  36. #define    isupper(c)    (_ctype[(unsigned char)(c)]&_CTu)
  37. #define    isxdigit(c)    (_ctype[(unsigned char)(c)]&_CTx)
  38. #define iswhite(c)    isspace(c)
  39.  
  40. #define    _toupper(c)    ((c)^0x20)
  41. #define    _tolower(c)    ((c)^0x20)
  42. #define    toascii(c)    ((c)&0x7F)
  43.  
  44. #ifdef __GNUC__
  45. /* use safe versions */
  46.  
  47. #if 0 /* do not define, these are routines in ctype.c as they should be */
  48. #define    toupper(c) \
  49.     ({typeof(c) _c = (c);     \
  50.         islower(_c) ? (_c^0x20) : _c; })
  51. #define    tolower(c)  \
  52.     ({typeof(c) _c = (c);     \
  53.         isupper(_c) ? (_c^0x20) : _c; })
  54. #endif /* 0 */
  55.  
  56. #define toint(c)    \
  57.     ({typeof(c) _c = (c);     \
  58.         (_c <= '9') ? (_c - '0') : (toupper(_c) - 'A'); })
  59. #define isodigit(c) \
  60.     ({typeof(c) _c = (c);      \
  61.         (_c >='0') && (_c<='7'); })
  62. #define iscymf(c)   \
  63.     ({typeof(c) _c = (c);      \
  64.         isalpha(_c) || (_c == '_'); })
  65. #define iscym(c)    \
  66.     ({typeof(c) _c = (c);      \
  67.         isalnum(_c) || (_c == '_'); })
  68.  
  69. #else /* you know what */
  70.  
  71. #if 0 /* see above */
  72. #define    toupper(c)    (islower(c) ? (c)^0x20 : (c))
  73. #define    tolower(c)    (isupper(c) ? (c)^0x20 : (c))
  74. #endif
  75.  
  76. #define toint(c)    ( (c) <= '9' ? (c) - '0' : toupper(c) - 'A' )
  77. #define isodigit(c)    ( (c)>='0' && (c)<='7' )
  78. #define iscymf(c)    (isalpha(c) || ((c) == '_') )
  79. #define iscym(c)    (isalnum(c) || ((c) == '_') )
  80.  
  81. #endif /* __GNUC__ */
  82.  
  83. __EXTERN int    toupper    __PROTO((int));
  84. __EXTERN int     tolower    __PROTO((int));
  85.  
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89.  
  90. #endif /* _CTYPE_H */
  91.